/*
 * Ext GWT 2.2.4 - Ext for GWT
 * Copyright(c) 2007-2010, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
package id.co.rho.scoring.cid.client.helper;

import com.extjs.gxt.ui.client.Style.HideMode;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;

public class Entry extends BaseTreeModel {

    private String name;
    private boolean fill;
    private boolean closable = true;
    private HideMode hideMode = HideMode.DISPLAY;

    public Entry(String name, LayoutContainer viewContainer, String image) {
        this.name = name;
        set("name", name);
        set("image", image);
        set("viewContainer", viewContainer);
    }

    public Entry(String name, LayoutContainer viewContainer, String image, boolean fill) {
        this(name, viewContainer, image);
        this.fill = fill;
    }

    public Entry(String name, LayoutContainer viewContainer, String image, boolean fill, boolean closable) {
        this(name, viewContainer, image, fill);
        this.closable = closable;
    }

    public Entry(String name, LayoutContainer viewContainer, String image, boolean fill, boolean closable, HideMode hideMode) {
        this(name, viewContainer, image, fill, closable);
        this.setHideMode(hideMode);
    }

    protected Entry() {

    }

    public Entry(String name) {
        set("name", name);
    }

    public Entry(String name, BaseTreeModel[] children) {
        this(name);
        for (int i = 0; i < children.length; i++) {
            add(children[i]);
        }
    }

    public LayoutContainer getViewContainer() {
        return (LayoutContainer) get("viewContainer");
    }

    public String getId() {
        if (name.equals("% Columns")) {
            return "percentcolumns";
        }
        return name.replaceAll(" ", "").toLowerCase();
    }

    public HideMode getHideMode() {
        return hideMode;
    }

    public String getName() {
        return (String) get("name");
    }

    @SuppressWarnings("tidak digunakan")
    public String getSourceUrl() {
        Object o = (Object) get("viewContainer");
        String name = o.getClass().getName();

        name = name.substring(name.lastIndexOf("viewContainers.") + 9);
        name = "code/" + name + ".html";
        name = name.replaceFirst("\\.", "/");

//    if (!ScaffoldExtDesktopShell.isExplorer()) {
//      name = "../../" + name;
//    }

        return name;
    }

    public boolean isClosable() {
        return closable;
    }

    public boolean isFill() {
        return fill;
    }

    public void setFill(boolean fill) {
        this.fill = fill;
    }

    public void setHideMode(HideMode hideMode) {
        this.hideMode = hideMode;
    }

    public String toString() {
        return getName();
    }

}
